<template>
  <div class="comment-reply">
    <van-nav-bar
      :title="comment.reply_count ? `${comment.reply_count} 条评论` : '暂无评论'"
    >
      <template #left>
        <van-icon name="cross" size="18" @click="$emit('close-reply')" />
      </template>
    </van-nav-bar>

    <div class="scroll-wrap">
      <comment-item :item="comment"/>

      <van-cell title="所有回复" />

      <article-comment
        :list="list"
        :artId="comment.com_id"
        type="c"
      />
    </div>

    <div class="submit-wrap">
      <van-button type="default" size="small" round @click="showSubmitFlag = true">发表评论</van-button>
    </div>

    <van-popup
      v-model="showSubmitFlag"
      position="bottom"
    >
      <comment-post
        :target="comment.com_id"
        @onpost-success="onpostSuccess"
      />
    </van-popup>
  </div>
</template>

<script>
import ArticleComment from './article-comment.vue'
import CommentItem from './comment-item.vue'
import CommentPost from './comment-post.vue'

export default {
  name: 'comment-reply',
  props: ['comment'],
  components: {
    CommentItem,
    ArticleComment,
    CommentPost
  },
  data() {
    return {
      showSubmitFlag: false,
      list: []
    }
  },
  methods: {
    onpostSuccess(res) {
      this.showSubmitFlag = false
      this.list.unshift(res.data.data.new_obj)
    }
  }
}
</script>

<style lang="less" scoped>
.comment-reply {
  .van-icon {
    color: #333;
  }

  .scroll-wrap {
    position: fixed;
    top: calc(5% + 92px);
    left: 0;
    right: 0;
    bottom: 88px;
    overflow-y: auto;
  }

  .submit-wrap {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 88px;
    justify-content: center;
    align-items: center;
    background: #fff;
    border-top: 1px solid #ebedf0;

    .van-button {
      width: 60%;
    }
  }
}
</style>
